package handlers;

import java.util.List;
import java.util.Random;

import influence_radii.Linear;
import map.GameMap;
import map.GameWorld;
import map.Position;
import entity.Entity;

public class RemoveTrapHandler {
	private Entity remover = null;
	
	public RemoveTrapHandler(Entity remover) {
		this.remover = remover;
	}
	
	public void attemptTrapRemoval(int level) {
		Position pos = new Position(remover.getPosition());
		Linear effect = new Linear(remover.getDirection());
		List<Position> positions = effect.getRelAppsPts(1);
		pos.add(positions.get(0));
		
		GameMap map = GameWorld.getInstance().getCurrentMap();
		if(map.hasTrap(pos)) {
			if(compute(level)) {
				map.removeTrap(pos);
				System.out.println("Successfully removed trap");
			}
			else {
				System.out.println("Oops failed to remove Trap");
			}
		}
		
	}
	public boolean compute(int level) {
		level = level + 8;
		int max = 10;
		int[] values = new int[max];
		int result;
		Random ran = new Random();

		for(int i=1; i<values.length; i++)
			values[i-1] = i;
		
		result = (1 - (max - level)/(level))*10;
		if (result > max)
			result = max;
		int num = ran.nextInt(max) + 1;
		for(int i=0; i < result; i++) {
			if(values[i] == num)
				return true;
		}
		return false;
	}
}
